﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using SIS.ENT;
using SIS.BLL;
using System.Globalization;
using SIS.Utilities;
using SIS.UI;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class Employee_EmployeeEntry : System.Web.UI.Page
{
    #region "Events"
    public Common _common = new Common();
    public int _UserAccountKey = -1;
    public int _SchoolKey = -1;


    protected void Page_Load(object sender, EventArgs e)
    {

        lblTopMessage.Text = DateTime.Now.ToString();
        if (!Page.IsPostBack)
        {
            SIS.Utilities.General.LoadDayDropdownList(ddlDOBDay);
            SIS.Utilities.General.LoadMonthDropdownList(ddlDOBMonth, 2);
            SIS.Utilities.General.LoadYearDropdownList(ddlDOBYear, (DateTime.Now.Year - 45), DateTime.Now.Year, 1);
            _common.LoadNationalityDDL(ddlNationality, string.Empty);
            _common.LoadTravelDocDDL(ddlTravelDocType, string.Empty);
            _common.LoadBloodGroupDDL(ddlBloodGroup, string.Empty);
            _common.LoadDrivingLicenseTypeDDL(ddlDrivingLicenceType, string.Empty);
            _common.LoadMartialStatusCodeDDL(ddlMaritalStatus, string.Empty);
            _common.LoadRaceCodeDDL(ddlRaceCode, string.Empty);
            _common.LoadReligionCodeDDL(ddlReligion, string.Empty);
            _common.LoadCurrencyCodeDDL(ddlCurrency, string.Empty);
            _common.LoadDesignationCodeDDL(ddlJobDesignation, string.Empty);
            _common.LoadPaymentTypeCodeCodeDDL(ddlpaymentType, string.Empty);
            _common.LoadParentStatusDDL(ddlParentStatus, string.Empty);

            _common.LoadCountryCodeDDL(ddlCountry, string.Empty);
            _common.LoadCountryCodeDDL(ddlPCountry, string.Empty);
            if (Request.Params["id"] != null)
            {

                if (Int32.TryParse(Request.Params["id"].ToString(), out _UserAccountKey))
                {

                    LoadEmployeeInfo(_UserAccountKey);
                }
                else
                {
                    lblTopMessage.Text = "Invalid Employee account ID.";
                }

                lblTopMessage.Text = DateTime.Now.ToString();
            }
            else
            {

                tbpDesignation.Visible = false;
                tbpSalary.Visible = false;
                tbpInfo3.Visible = false;
                tbpInfo4.Visible = false;
                tbpInfo5.Visible = false;
                lblExperienceHistory.Visible = false;
                lblHeaderQualification.Visible = false;
                lblOtherSkills.Visible = false;
                lblDesignation.Visible = false;
                lblSalary.Visible = false;


                 

            }
        }
        tbcEntry.ActiveTab = tbpInfo;
    }

    protected void btnAddNewEmployee_Click(object sender, EventArgs e)
    {
        Response.Redirect("EmployeeEntry.aspx");
    }

    protected void btnViewEmployeeList_Click(object sender, EventArgs e)
    {
        Response.Redirect("Employees-List.aspx");
    }

    protected void ddlSchoolList_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

    protected void ddlDistrict_SelectedIndexChanged(object sender, EventArgs e)
    {
        _common.LoadCityCodeDDL(ddlCity, Convert.ToInt32(ddlDistrict.SelectedValue), Convert.ToInt16(ddlCountry.SelectedValue), string.Empty);
        tbcEntry.ActiveTab = tbpInfo2;
    }

    protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlCountry.SelectedIndex >= 0)
        {
            _common.LoadDistrictCodeDDL(ddlDistrict, Convert.ToInt16(ddlCountry.SelectedItem.Value), string.Empty);
        }

        if (ddlDistrict.SelectedIndex >= 0)
        {
            _common.LoadCityCodeDDL(ddlCity, Convert.ToInt32(ddlDistrict.SelectedValue), Convert.ToInt16(ddlCountry.SelectedValue), string.Empty);
        }

        //System.Web.UI.ScriptManager.GetCurrent(this).SetFocus(this.tbpInfo2);
        tbcEntry.ActiveTab = tbpInfo2;
    }

    protected void ddlPDistrict_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlPDistrict.SelectedIndex >= 0)
        {
            _common.LoadCityCodeDDL(ddlPCity, Convert.ToInt32(ddlPDistrict.SelectedValue), Convert.ToInt16(ddlPCountry.SelectedValue), string.Empty);
            tbcEntry.ActiveTab = tbpInfo2;
        }
    }

    protected void ddlPCountry_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlPCountry.SelectedIndex >= 0)
        {
            _common.LoadDistrictCodeDDL(ddlPDistrict, Convert.ToInt16(ddlPCountry.SelectedItem.Value), string.Empty);
        }

        if (ddlDistrict.SelectedIndex > 0)
        {
            _common.LoadCityCodeDDL(ddlPCity, Convert.ToInt32(ddlPDistrict.SelectedValue), Convert.ToInt16(ddlPCountry.SelectedValue), string.Empty);
        }

        //System.Web.UI.ScriptManager.GetCurrent(this).SetFocus(this.tbpInfo2);
        tbcEntry.ActiveTab = tbpInfo2;
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        lblMessage.Text = "";
        bool _status = true;
        Page.Validate("EmployeeProfile");
        if (Page.IsValid)
        {
            UserAccountTable _account = new UserAccountTable();
            _account.UserAccountKey = Convert.ToInt32(lblUserAccountKey.Text);
            _account.SchoolKey = Convert.ToInt32(ddlSchoolList.Text);
            if (_account.UserAccountKey <= 0)
            {
                _account.UserAccountTypeCode = 800;
                _account.AuthCode = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 6);
                _account.AuthSalt = "EmployeeGUID" + _account.AuthCode;

                _account.UserAccountAlternateKey = txtFirstName.Text.Replace(" ", ".") + txtLastName.Text.Replace(" ", ".") + "@" + ddlSchoolList.Text;
                lblUserAuthCode.Text = _account.UserAccountAlternateKey + " With " + _account.AuthCode + " salted " + _account.AuthSalt;
                _account.Status = -1;

                UserAccountTableManager.Save(_account).ToString();

                if (_account.UserAccountKey <= 0)
                {
                    lblMessage.Text = "Saving user account was failed!";
                    _status = false;
                    return;
                }
                else
                {
                    lblUserAccountKey.Text = _account.UserAccountKey.ToString();
                }
            }


            EmployeeProfileTable _sprofile = new EmployeeProfileTable();
            EmployeeContactTable _scontact = new EmployeeContactTable();
            EmployeeAddressTable _sraddress = new EmployeeAddressTable();
            EmployeeAddressTable _spaddress = new EmployeeAddressTable();


            _sprofile.UserAccountKey = _account.UserAccountKey;
            _scontact.UserAccountKey = _account.UserAccountKey;
            _sraddress.UserAccountKey = _account.UserAccountKey;
            _spaddress.UserAccountKey = _account.UserAccountKey;


            _sprofile.EmployeeProfileKey = Convert.ToInt32(lblEmployeeProfileKey.Text);
            _scontact.EmployeeContactKey = Convert.ToInt32(lblEmployeeContactKey.Text);
            _sraddress.EmployeeAddressKey = Convert.ToInt32(lblEmployeeRAddressKey.Text);
            _spaddress.EmployeeAddressKey = Convert.ToInt32(lblEmployeePAddressKey.Text);

            _sprofile.FirstName = txtFirstName.Text;
            _sprofile.LastName = txtLastName.Text;
            _sprofile.OtherName = txtOtherName.Text;
            _sprofile.Gender = ddlGender.SelectedValue;

            DateTime _dtDOB = DateTime.Now;
            string _strDOB = string.Empty;
            _sprofile.DateOfBirth = new DateTime(1900, 1, 1);

            _strDOB = ddlDOBDay.Text + "/" + ddlDOBMonth.SelectedItem.Text + "/" + ddlDOBYear.Text.ToString();
            string StartDate = _strDOB;
            var dtfi1 = new DateTimeFormatInfo { ShortDatePattern = "dd-MMM-yyyy", DateSeparator = "-" };
            if (ddlDOBDay.SelectedValue == "-1" && ddlDOBMonth.SelectedValue == "-1" && ddlDOBYear.SelectedValue == "-1")
            {
                _sprofile.DateOfBirth = new DateTime(1900, 1, 1);
            }
            else
            {
                DateTime objStartDate = Convert.ToDateTime(_strDOB, dtfi1);
                if (SIS.Utilities.General.GetDateTime(_strDOB, out _dtDOB))
                {
                    _sprofile.DateOfBirth = objStartDate;
                }
                else
                {
                    //lblMessage.Text += _strDOB + " " + "NO User DOB: " + _dtDOB.ToString("dd/MMM/yyyy") + "<br/>";
                }
            }

            _sprofile.NRICNumber = txtNRICNumber.Text;

            _sprofile.DrivingLicenceType = Convert.ToInt16(ddlDrivingLicenceType.Text);
            _sprofile.DrivingLicenseNumber = txtDrivingLicenceNumber.Text;

            _sprofile.TravelDocumentType = Convert.ToInt16(ddlTravelDocType.Text);
            _sprofile.TravelDocumentNumber = txtTravelDocNumber.Text;

            _sprofile.BloodGroupCode = Convert.ToInt16(ddlBloodGroup.Text);
            _sprofile.MartialStatusCode = Convert.ToInt16(ddlMaritalStatus.Text);
            _sprofile.RaceCode = Convert.ToInt16(ddlRaceCode.Text);
            _sprofile.ReligionCode = Convert.ToInt16(ddlReligion.Text);
            _sprofile.NationalityCode = Convert.ToInt16(ddlNationality.Text);
            _sprofile.Hobby = txtHobby.Text;
            _sprofile.ParentStatus = Convert.ToInt16(ddlParentStatus.SelectedValue);
            _sprofile.PlaceOfBirth = txtPlaceOfBirth.Text;
            string SignInDate = txtJoinDate.Text;
            var dtInfo = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy HH:mm:ss", DateSeparator = "-" };
            DateTime objSignInDate = Convert.ToDateTime(SignInDate, dtInfo);
            _sprofile.JoinDate = objSignInDate;
            _sprofile.Status = 1;
            _sprofile.WebSiteUrl = txtWebsiteUrl.Text;
            _sprofile.CreatedDateTime = DateTime.Now;
            _sprofile.ModifiedDateTime = DateTime.Now;

            //_sprofile.UserAccountKey = -1;

            EmployeeProfileTableManager.Save(_sprofile);


            if (_sprofile.EmployeeProfileKey <= 0)
            {
                lblMessage.Text += "Saving profile was failed!<br/>";
                _status = false;
                //lblStudentProfileKey.Text = "-1";
            }
            else
            {
                lblEmployeeProfileKey.Text = _sprofile.EmployeeProfileKey.ToString();

            }

            //if (_sprofile.EmployeeProfileKey > 0 && FormStatus == "OLD")             
            //{
            _scontact.EmailAddress = txtEmailAddress.Text;
            _scontact.MobileNumber = txtMobileNumber.Text;
            _scontact.HomePhoneNumber = txtHomePhoneNumber.Text;
            _scontact.OtherNumber = txtOtherContactNumber.Text;
            _scontact.OfficePhoneNumber = txtOfficeNumber.Text;
            _scontact.FaxNumber = txtFaxNumber.Text;
            _scontact.Status = 1;
            _scontact.CreatedDateTime = DateTime.Now;
            _scontact.ModifiedDateTime = DateTime.Now;
            EmployeeContactTableManager.Save(_scontact);


            if (_scontact.EmployeeContactKey <= 0)
            {
                lblMessage.Text += "Saving contact was failed!<br/>";
                _status = false;
                //lblStudentContactKey.Text = "-1";
            }
            else
            {
                lblEmployeeContactKey.Text = _scontact.EmployeeContactKey.ToString();
            }

            //Resident Address
            _sraddress.UnitNo = txtUnitNo.Text;
            _sraddress.StreetName = txtStreetName.Text;
            _sraddress.CountryCode = Convert.ToInt16(ddlCountry.Text);
            _sraddress.DistrictCode = Convert.ToInt16(ddlDistrict.Text);
            _sraddress.CityCode = Convert.ToInt16(ddlCity.Text);
            _sraddress.PostalCode = txtPostCode.Text;
            _sraddress.AddressTypeCode = 1;
            _sraddress.Status = 1;
            _sraddress.CreatedDateTime = DateTime.Now;
            _sraddress.ModifiedDateTime = DateTime.Now;
            EmployeeAddressTableManager.Save(_sraddress);

            if (_sraddress.EmployeeAddressKey <= 0)
            {
                lblMessage.Text += "Saving Resident address was failed!<br/>";
                _status = false;
                //lblStudentAddressKey.Text = "-1";
            }
            else
            {
                lblEmployeeRAddressKey.Text = _sraddress.EmployeeAddressKey.ToString();
            }

            //Permanent Address
            if (chkPSameAsResident.Checked)
            {
                _spaddress.UnitNo = txtUnitNo.Text;
                _spaddress.StreetName = txtStreetName.Text;
                _spaddress.CountryCode = Convert.ToInt16(ddlCountry.Text);
                _spaddress.DistrictCode = Convert.ToInt16(ddlDistrict.Text);
                _spaddress.CityCode = Convert.ToInt16(ddlCity.Text);
                _spaddress.PostalCode = txtPostCode.Text;
                _spaddress.Status = 1;
                _spaddress.CreatedDateTime = DateTime.Now;
                _spaddress.ModifiedDateTime = DateTime.Now;
            }
            else
            {
                _spaddress.UnitNo = txtPUnitNo.Text;
                _spaddress.StreetName = txtPStreetName.Text;
                _spaddress.CountryCode = Convert.ToInt16(ddlPCountry.Text);
                _spaddress.DistrictCode = Convert.ToInt16(ddlPDistrict.Text);
                _spaddress.CityCode = Convert.ToInt16(ddlPCity.Text);
                _spaddress.PostalCode = txtPPostCode.Text;
                _spaddress.Status = 1;
                _spaddress.CreatedDateTime = DateTime.Now;
                _spaddress.ModifiedDateTime = DateTime.Now;
            }

            _spaddress.AddressTypeCode = 2;

            EmployeeAddressTableManager.Save(_spaddress);

            if (_spaddress.EmployeeAddressKey <= 0)
            {
                lblMessage.Text += "Saving Permanent address was failed!<br/>";
                _status = false;
                //lblStudentAddressKey.Text = "-1";
            }
            else
            {
                lblEmployeePAddressKey.Text = _spaddress.EmployeeAddressKey.ToString();
            }
            if (_sprofile.EmployeeProfileKey > 0 && _account.UserAccountKey > 0)
            {
                tbpDesignation.Visible = true;
                tbpSalary.Visible = true;
                tbpInfo3.Visible = true;
                tbpInfo4.Visible = true;
                tbpInfo5.Visible = true;
                lblExperienceHistory.Visible = true;
                lblHeaderQualification.Visible = true;
                lblOtherSkills.Visible = true;
                lblDesignation.Visible = true;
                lblSalary.Visible = true;
            }


            //}

            /////******************


            //int count = 0;
            ////Save Job Experience
            //DataTable lDT = new DataTable();
            //lDT = (DataTable)Session["JobExperiencesDT"];
            //foreach (DataRow lDR in lDT.Rows)
            //{
            //    EmployeeJobExperiencesTable objEmployeeJobExp = new EmployeeJobExperiencesTable();
            //    if (Convert.ToString(lDR["Status"]) != "Delete")
            //    {
            //        if (Convert.ToString(lDR["Status"]) == "New")
            //        {
            //            objEmployeeJobExp.EmployeeJobExperienceKey = Convert.ToInt32(-1);
            //        }
            //        else
            //        {
            //            objEmployeeJobExp.EmployeeJobExperienceKey = (int)lDR["EmployeeJobExperienceKey"];
            //        }

            //        objEmployeeJobExp.UserAccountKey = _account.UserAccountKey;
            //        objEmployeeJobExp.PreviousEmployer = lDR["PreviousEmployer"].ToString();
            //        objEmployeeJobExp.StartDate = (DateTime)lDR["StartDate"];
            //        objEmployeeJobExp.EndDate = (DateTime)lDR["EndDate"];
            //        objEmployeeJobExp.Position = Convert.ToString(lDR["Position"]);
            //        objEmployeeJobExp.BasicSalary = Convert.ToDecimal(lDR["BasicSalary"]);
            //        objEmployeeJobExp.RefereeName = Convert.ToString(lDR["RefereeName"]);
            //        objEmployeeJobExp.RefereeAddress = Convert.ToString(lDR["RefereeAddress"]);
            //        objEmployeeJobExp.RefereeEmail = Convert.ToString(lDR["RefereeEmail"]);
            //        objEmployeeJobExp.RefereeContact = Convert.ToString(lDR["RefereeContact"]);
            //        objEmployeeJobExp.Remarks = Convert.ToString(lDR["Remarks"]);
            //        objEmployeeJobExp.Status = 1;
            //        objEmployeeJobExp.CreatedDateTime = DateTime.Now;
            //        objEmployeeJobExp.ModifiedDateTime = DateTime.Now;

            //        EmployeeJobExperiencesTableManager.Save(objEmployeeJobExp);
            //        if (objEmployeeJobExp.EmployeeJobExperienceKey <= 0)
            //        {
            //            lblMessage.Text += "Saving Job Experiences was failed!<br/>";
            //            _status = false;
            //        }
            //        else
            //        {
            //            count++;
            //        }
            //    }
            //    else
            //    {
            //        bool lresult = EmployeeJobExperiencesTableManager.Delete((int)lDR["EmployeeJobExperienceKey"]);
            //    }
            //}
            //if (count > 0)
            //{
            //    lblEmployeeJobExperienceKey.Text = "Saved Successfully.Total Record" + count.ToString();
            //}


            //count = 0;
            ////Save Employee Designation
            //DataTable lDesignationDT = new DataTable();
            //lDesignationDT = (DataTable)Session["EmployeeDesignationsDT"];
            //foreach (DataRow lDR in lDesignationDT.Rows)
            //{
            //    EmployeeDesignationTable objEmployeeDesignation = new EmployeeDesignationTable();
            //    if (Convert.ToString(lDR["Status"]) != "Delete")
            //    {
            //        if (Convert.ToString(lDR["Status"]) == "New")
            //        {
            //            objEmployeeDesignation.EmployeeDesignationKey = Convert.ToInt32(-1);//(int)lDR["EmployeeDesignationKey"];
            //        }
            //        else
            //        {
            //            objEmployeeDesignation.EmployeeDesignationKey = (int)lDR["EmployeeDesignationKey"];
            //        }

            //        objEmployeeDesignation.UserAccountKey = _account.UserAccountKey;
            //        objEmployeeDesignation.JobDesignationCode = (Int16)lDR["JobDesignationCode"];
            //        objEmployeeDesignation.StartDate = (DateTime)lDR["StartDate"];
            //        objEmployeeDesignation.EndDate = (DateTime)lDR["EndDate"];
            //        objEmployeeDesignation.JobDescriptionDetail = Convert.ToString(lDR["JobDescriptionDetail"]);
            //        objEmployeeDesignation.Active = (Boolean)(lDR["Active"]);
            //        objEmployeeDesignation.Remarks = Convert.ToString(lDR["Remarks"]);
            //        objEmployeeDesignation.Status = 1;
            //        objEmployeeDesignation.CreatedDateTime = DateTime.Now;
            //        objEmployeeDesignation.ModifiedDateTime = DateTime.Now;

            //        EmployeeDesignationTableManager.Save(objEmployeeDesignation);
            //        if (objEmployeeDesignation.EmployeeDesignationKey <= 0)
            //        {
            //            lblMessage.Text += "Saving Employee Designation was failed!<br/>";
            //            _status = false;
            //        }
            //        else
            //        {
            //            count++;
            //        }
            //    }
            //    else
            //    {
            //        bool lResult = EmployeeDesignationTableManager.Delete((int)lDR["EmployeeDesignationKey"]);
            //    }
            //}
            //if (count > 0)
            //{
            //    lblJobDesignationKey.Text = "Saved Successfully.";
            //}


            //count = 0;
            ////Save Salary
            //DataTable lSalaryDT = new DataTable();
            //lSalaryDT = (DataTable)Session["EmployeeSalaryDT"];
            //foreach (DataRow lDR in lSalaryDT.Rows)
            //{
            //    EmployeeSalaryTable objEmployeeSalary = new EmployeeSalaryTable();
            //    if (Convert.ToString(lDR["Status"]) != "Delete")
            //    {
            //        if (Convert.ToString(lDR["Status"]) == "New")
            //        {
            //            objEmployeeSalary.EmployeeSalaryKey = Convert.ToInt32(-1);
            //        }
            //        else
            //        {
            //            objEmployeeSalary.EmployeeSalaryKey = (int)lDR["EmployeeSalaryKey"];
            //        }

            //        objEmployeeSalary.UserAccountKey = _account.UserAccountKey;
            //        objEmployeeSalary.PaymentTypeCode = (Int16)lDR["PaymentTypeCode"];
            //        objEmployeeSalary.StartDate = (DateTime)lDR["StartDate"];
            //        objEmployeeSalary.EndDate = (DateTime)lDR["EndDate"];
            //        objEmployeeSalary.CurrencyCode = (Int16)lDR["CurrencyCode"];
            //        objEmployeeSalary.Amount = Convert.ToDecimal(lDR["Amount"]);
            //        objEmployeeSalary.Allotment1 = Convert.ToDecimal(lDR["Allotment1"]);
            //        objEmployeeSalary.Allotment2 = Convert.ToDecimal(lDR["Allotment2"]);
            //        objEmployeeSalary.Active = (Boolean)(lDR["Active"]);
            //        objEmployeeSalary.Remarks = Convert.ToString(lDR["Remarks"]);
            //        objEmployeeSalary.Status = 1;
            //        objEmployeeSalary.CreatedDateTime = DateTime.Now;
            //        objEmployeeSalary.ModifiedDateTime = DateTime.Now;

            //        EmployeeSalaryTableManager.Save(objEmployeeSalary);
            //        if (objEmployeeSalary.EmployeeSalaryKey <= 0)
            //        {
            //            lblMessage.Text += "Saving Employee Salary was failed!<br/>";
            //            _status = false;
            //        }
            //        else
            //        {
            //            count++;
            //        }
            //    }
            //    else
            //    {
            //        bool lResult = EmployeeSalaryTableManager.Delete((int)lDR["EmployeeSalaryKey"]);
            //    }
            //}
            //if (count > 0)
            //{
            //    lblSalaryKey.Text = "Saved Successfully.Total Record" + count.ToString();
            //}

            //QualificationDT

            //    count = 0;
            //    //Save qUALIFICATION
            //    DataTable lQualificationDT = new DataTable();
            //    lQualificationDT = (DataTable)Session["QualificationDT"];
            //    foreach (DataRow lDR in lQualificationDT.Rows)
            //    {
            //        EmployeeQualtificationTable objEmployeeQualify = new EmployeeQualtificationTable();
            //        if (Convert.ToString(lDR["Status"]) != "Delete")
            //        {
            //            if (Convert.ToString(lDR["Status"]) == "New")
            //            {
            //                objEmployeeQualify.EmployeeQualtificationKey = Convert.ToInt32(-1);//(int)lDR["EmployeeDesignationKey"];
            //            }
            //            else
            //            {
            //                objEmployeeQualify.EmployeeQualtificationKey = (int)lDR["EmployeeQualtificationKey"];
            //            }

            //            objEmployeeQualify.UserAccountKey = _account.UserAccountKey;
            //            objEmployeeQualify.QualificationName = Convert.ToString(lDR["QualificationName"]);
            //            objEmployeeQualify.Organization = Convert.ToString(lDR["Organization"]);
            //            objEmployeeQualify.GradeLevel = Convert.ToString(lDR["GradeLevel"]);
            //            objEmployeeQualify.Year = Convert.ToString(lDR["Year"]);
            //            objEmployeeQualify.Others = Convert.ToString(lDR["Others"]);
            //            objEmployeeQualify.Status = 1;
            //            objEmployeeQualify.CreatedDateTime = DateTime.Now;
            //            objEmployeeQualify.ModifiedDateTime = DateTime.Now;

            //            EmployeeQualtificationTableManager.Save(objEmployeeQualify);
            //            if (objEmployeeQualify.EmployeeQualtificationKey <= 0)
            //            {
            //                lblMessage.Text += "Saving Employee Qualification was failed!<br/>";
            //                _status = false;
            //            }
            //            else
            //            {
            //                count++;
            //            }
            //        }
            //        else
            //        {
            //            bool lResult = EmployeeQualtificationTableManager.Delete((int)lDR["EmployeeQualtificationKey"]);
            //        }
            //    }
            //    if (count > 0)
            //    {
            //        lblQualificationKey.Text = "Saved Successfully. ";
            //    }

            //    //EmployeeOtherSkillsDT
            //    DataTable lSkillDT = new DataTable();
            //    lSkillDT = (DataTable)Session["EmployeeOtherSkillsDT"];
            //    foreach (DataRow lDR in lSkillDT.Rows)
            //    {
            //        EmployeeOtherSkillsTable objEmployeeSkill = new EmployeeOtherSkillsTable();
            //        if (Convert.ToString(lDR["Status"]) != "Delete")
            //        {
            //            if (Convert.ToString(lDR["Status"]) == "New")
            //            {
            //                objEmployeeSkill.EmployeeOtherSkillsKey = Convert.ToInt32(-1);
            //            }
            //            else
            //            {
            //                objEmployeeSkill.EmployeeOtherSkillsKey = (int)lDR["EmployeeOtherSkillsKey"];
            //            }

            //            objEmployeeSkill.UserAccountKey = _account.UserAccountKey;
            //            objEmployeeSkill.SkillName = Convert.ToString(lDR["SkillName"]);
            //            objEmployeeSkill.Organization = Convert.ToString(lDR["Organization"]);
            //            objEmployeeSkill.SkillLevel = Convert.ToString(lDR["SkillLevel"]);
            //            objEmployeeSkill.NoOfYear = Convert.ToString(lDR["NoOfYear"]);
            //            objEmployeeSkill.Others = Convert.ToString(lDR["Others"]);
            //            objEmployeeSkill.Status = 1;
            //            objEmployeeSkill.CreatedDateTime = DateTime.Now;
            //            objEmployeeSkill.ModifiedDateTime = DateTime.Now;

            //            EmployeeOtherSkillsTableManager.Save(objEmployeeSkill);
            //            if (objEmployeeSkill.EmployeeOtherSkillsKey <= 0)
            //            {
            //                lblMessage.Text += "Saving Employee Skill was failed!<br/>";
            //                _status = false;
            //            }
            //            else
            //            {
            //                count++;
            //            }
            //        }
            //        else
            //        {
            //            bool lresult = EmployeeOtherSkillsTableManager.Delete((int)lDR["EmployeeOtherSkillsKey"]);
            //        }

            //    }
            //    if (count > 0)
            //    {
            //        lblSkillKey.Text = "Saved Successfully. ";
            //    }

            //    if (lblMessage.Text.Length == 0)
            //    {
            //        lblTopMessage.Text = "Saving was succeeded at " + DateTime.Now.ToString("dd/MMM/yyyy hh:mm tt");
            //        lblMessage.Text = "Saving was succeeded at " + DateTime.Now.ToString("dd/MMM/yyyy hh:mm tt");
            //    }

            //    if (lblEmployeeProfileKey.Text != "-1")
            //    {
            //        btnUpdatePhoto.Visible = true;
            //    }
            //    else
            //    {
            //        btnUpdatePhoto.Visible = false;
            //    }
        }
    }

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        if (txtPreviousEmployer.Text.Equals(String.Empty))
        {
            lblMessage.Text = "Partner School,Start Date,End Date should not blank.";

        }
        else
        {
            if (txtStartDate.Text.Equals(String.Empty) || txtEndDate.Text.Equals(String.Empty))
            {

                lblMessage.Text = "Start Date,End Date should not blank.";
            }
        }
        if (!txtPreviousEmployer.Text.Equals(String.Empty) && !(txtStartDate.Text.Equals(String.Empty) && txtEndDate.Text.Equals(String.Empty)))
        {
            Page.Validate("JobExperience");
            if (Page.IsValid)
            {

                Int32 JobExpeienceKey = 0;
                if (btnAdd.Text == "Add New")
                {
                    JobExpeienceKey = Convert.ToInt32(-1);
                    AddEmployeeExperience(JobExpeienceKey, txtPreviousEmployer.Text, txtStartDate.Text, txtEndDate.Text, txtPosition.Text, txtSalary.Text, txtRefereeName.Text, txtRefereeAddress.Text, txtRefereeEmail.Text, txtRefereeContact.Text, txtRemarks.Text);
                    //AddToTempTable(txtPreviousEmployer.Text, txtStartDate.Text, txtEndDate.Text, txtPosition.Text, txtSalary.Text, txtRefereeName.Text, txtRefereeAddress.Text, txtRefereeEmail.Text, txtRefereeContact.Text, txtRemarks.Text);
                }
                else
                {

                    JobExpeienceKey = Convert.ToInt32(lblJobExperienceKey.Text);
                    AddEmployeeExperience(JobExpeienceKey, txtPreviousEmployer.Text, txtStartDate.Text, txtEndDate.Text, txtPosition.Text, txtSalary.Text, txtRefereeName.Text, txtRefereeAddress.Text, txtRefereeEmail.Text, txtRefereeContact.Text, txtRemarks.Text);
                    btnAdd.Text = "Add New"; //reset
                    lblJobExperienceKey.Text = "-1"; //reset
                    //UpdateTempTable(lblJobExperienceKey.Text, lblAccountKey.Text, txtPreviousEmployer.Text, txtStartDate.Text, txtEndDate.Text, txtPosition.Text, Convert.ToDecimal(txtSalary.Text), txtRefereeName.Text, txtRefereeAddress.Text, txtRefereeEmail.Text, txtRefereeContact.Text, txtRemarks.Text);
                }
            }
        }
        tbcEntry.ActiveTab = tbpInfo3;

    }

    private void AddEmployeeExperience(int EmployeeJobExperienceKey, string PreviousEmployer, string dStartDate, string dEndDate, string Position, string BasicSalary, string RefereeName, string RefereeAddress, string RefereeEmail, string RefereeContact, string Remarks)
    {

        EmployeeJobExperiencesTable objEmployeeJobExp = new EmployeeJobExperiencesTable();
        UserAccountTable _account = new UserAccountTable();
        _account.UserAccountKey = Convert.ToInt32(lblUserAccountKey.Text);
        objEmployeeJobExp.UserAccountKey = _account.UserAccountKey;
        string StartDate = dStartDate;
        var dtfi1 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy HH:mm:ss", DateSeparator = "-" };
        DateTime objStartDate = Convert.ToDateTime(StartDate, dtfi1);

        string EndDate = dEndDate;
        var dtfi2 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy HH:mm:ss", DateSeparator = "-" };
        DateTime objEndDate = Convert.ToDateTime(EndDate, dtfi2);

        objEmployeeJobExp.EmployeeJobExperienceKey = EmployeeJobExperienceKey;
        objEmployeeJobExp.PreviousEmployer = PreviousEmployer;
        objEmployeeJobExp.StartDate = objStartDate;
        objEmployeeJobExp.EndDate = objEndDate;
        objEmployeeJobExp.Position = Position;
        objEmployeeJobExp.BasicSalary = Convert.ToDecimal(BasicSalary);
        objEmployeeJobExp.RefereeName = Convert.ToString(RefereeName);
        objEmployeeJobExp.RefereeAddress = Convert.ToString(RefereeAddress);
        objEmployeeJobExp.RefereeEmail = Convert.ToString(RefereeEmail);
        objEmployeeJobExp.RefereeContact = Convert.ToString(RefereeContact);
        objEmployeeJobExp.Remarks = Convert.ToString(Remarks);
        objEmployeeJobExp.Status = 1;
        objEmployeeJobExp.CreatedDateTime = DateTime.Now;
        objEmployeeJobExp.ModifiedDateTime = DateTime.Now;

        EmployeeJobExperiencesTableManager.Save(objEmployeeJobExp);
        if (objEmployeeJobExp.EmployeeJobExperienceKey <= 0)
        {
            lblMessage.Text += "Saving Job Experiences was failed!<br/>";
        }
        else
        {
            ClearJobExperienceRecord();
            FillEmployeeJobExperience(_account.UserAccountKey);
        }

    }

    protected void btnQualifyAdd_Click(object sender, EventArgs e)
    {
        if (txtQualification2.Text.Equals(String.Empty))
        {
            lblMessage.Text = "Qualification should not blank.";

        }
        else
        {

            //Page.Validate("EmployeeProfile");
            //if (Page.IsValid)
            //{
            Int32 QualificationKey = 0;
            if (btnQualifyAdd.Text == "Add New")
            {
                QualificationKey = Convert.ToInt32(-1);
                AddQualification(QualificationKey, txtQualification2.Text, txtOrganization.Text, txtYear.Text, txtGradelevel.Text, txtQualifyOthers.Text);
                //AddToQualifyTempTable(txtQualification2.Text, txtOrganization.Text, txtYear.Text, txtGradelevel.Text, txtQualifyOthers.Text);
            }
            else
            {
                QualificationKey = Convert.ToInt32(lblQualificationKey.Text);
                AddQualification(QualificationKey, txtQualification2.Text, txtOrganization.Text, txtYear.Text, txtGradelevel.Text, txtQualifyOthers.Text);
                btnQualifyAdd.Text = "Add New"; //reset
                lblQualificationKey.Text = "-1"; //reset
                //UpdateQualificationTempTable(lblQualificationKey.Text, txtQualification2.Text, txtOrganization.Text, txtYear.Text, txtGradelevel.Text, txtQualifyOthers.Text);
            }
            //}
        }
        tbcEntry.ActiveTab = tbpInfo4;

    }

    private void AddQualification(int EmployeeQualtifiKey, string QualificationName, string Organization, string Year, string GradeLevel, string Others)
    {

        EmployeeQualtificationTable objEmployeeQualification = new EmployeeQualtificationTable();
        UserAccountTable _account = new UserAccountTable();
        _account.UserAccountKey = Convert.ToInt32(lblUserAccountKey.Text);
        objEmployeeQualification.UserAccountKey = _account.UserAccountKey;


        objEmployeeQualification.EmployeeQualtificationKey = EmployeeQualtifiKey;
        objEmployeeQualification.QualificationName = QualificationName;
        objEmployeeQualification.Organization = Organization;
        objEmployeeQualification.Year = Year;
        objEmployeeQualification.GradeLevel = GradeLevel;
        objEmployeeQualification.Others = Others;
        objEmployeeQualification.Status = 1;
        objEmployeeQualification.CreatedDateTime = DateTime.Now;
        objEmployeeQualification.ModifiedDateTime = DateTime.Now;

        EmployeeQualtificationTableManager.Save(objEmployeeQualification);
        if (objEmployeeQualification.EmployeeQualtificationKey <= 0)
        {
            lblMessage.Text += "Saving Employee Qualification was failed!<br/>";
        }
        else
        {
            ClearQualificationRecord();
            FillEmployeeQualification(_account.UserAccountKey);
        }

    }

    protected void btnSkillAdd_Click(object sender, EventArgs e)
    {
        if (txtSkill.Text.Equals(String.Empty))
        {
            lblMessage.Text = "Skill may not blank";

        }
        else
        {

            //Page.Validate("EmployeeProfile");
            //if (Page.IsValid)
            //{
            Int32 OtherSkillKey = 0;

            if (btnSkillAdd.Text == "Add New")
            {
                OtherSkillKey = Convert.ToInt32(-1);
                AddOtherSkills(OtherSkillKey, txtSkill.Text, txtSkillOrganization.Text, txtNoOfYear.Text, txtSkillLevel.Text, txtSkillOthers.Text);
                //AddToSkillTempTable(txtSkill.Text, txtSkillOrganization.Text, txtNoOfYear.Text, txtSkillLevel.Text, txtSkillOthers.Text);
            }
            else
            {
                OtherSkillKey = Convert.ToInt32(lblSkillKey.Text);
                AddOtherSkills(OtherSkillKey, txtSkill.Text, txtSkillOrganization.Text, txtNoOfYear.Text, txtSkillLevel.Text, txtSkillOthers.Text);
                btnSkillAdd.Text = "Add New"; //reset
                lblSkillKey.Text = "-1"; //reset
                //UpdateSkillTempTable(lblSkillKey.Text, txtSkill.Text, txtSkillOrganization.Text, txtNoOfYear.Text, txtSkillLevel.Text, txtSkillOthers.Text);
            }
            //}
        }
        tbcEntry.ActiveTab = tbpInfo5;

    }

    private void AddOtherSkills(int EmployeeOtherSkillKey, string SkillName, string Organization, string NoOfYear, string SkillLevel, string Others)
    {

        EmployeeOtherSkillsTable objEmployeeOtherSkill = new EmployeeOtherSkillsTable();
        UserAccountTable _account = new UserAccountTable();
        _account.UserAccountKey = Convert.ToInt32(lblUserAccountKey.Text);
        objEmployeeOtherSkill.UserAccountKey = _account.UserAccountKey;


        objEmployeeOtherSkill.EmployeeOtherSkillsKey = EmployeeOtherSkillKey;
        objEmployeeOtherSkill.SkillName = SkillName;
        objEmployeeOtherSkill.SkillLevel = SkillLevel;
        objEmployeeOtherSkill.Organization = Organization;
        objEmployeeOtherSkill.NoOfYear = NoOfYear;
        objEmployeeOtherSkill.Others = Others;
        objEmployeeOtherSkill.Status = 1;
        objEmployeeOtherSkill.CreatedDateTime = DateTime.Now;
        objEmployeeOtherSkill.ModifiedDateTime = DateTime.Now;

        EmployeeOtherSkillsTableManager.Save(objEmployeeOtherSkill);
        if (objEmployeeOtherSkill.EmployeeOtherSkillsKey <= 0)
        {
            lblMessage.Text += "Saving Employee Other Skill was failed!<br/>";
        }
        else
        {
            ClearOtherSkillRecord();
            FillEmployeeOtherSkill(_account.UserAccountKey);
        }

    }

    protected void btnDesignationAdd_Click(object sender, EventArgs e)
    {
        if (txtDesignationDesc.Text.Equals(String.Empty))
        {
            lblMessage.Text = "Designation should not blank.";

        }

        else
        {
            if (txtDesgnationStartDate.Text.Equals(String.Empty) || txtDesgnationEndDate.Text.Equals(String.Empty))
            {

                lblMessage.Text = "Start Date,End Date should not blank.";
            }
        }
        if (!txtDesignationDesc.Text.Equals(String.Empty) && !(txtDesgnationStartDate.Text.Equals(String.Empty) && txtDesgnationEndDate.Text.Equals(String.Empty)))
        {

            Page.Validate("vgDesignation");
            if (Page.IsValid)
            {
                bool Active = true;
                int JobDesignationKey = 0;
                if (chkDesignation.Checked == false)
                {
                    Active = false;
                }
                if (btnDesignationAdd.Text == "Add New")
                {
                    JobDesignationKey = Convert.ToInt32(-1);
                    AddDesignation(JobDesignationKey, Convert.ToInt16(ddlJobDesignation.SelectedValue), txtDesignationDesc.Text, txtDesgnationStartDate.Text, txtDesgnationEndDate.Text, txtDesignationRemark.Text, Active);
                    //AddToDesignationTempTable(Convert.ToInt16(ddlJobDesignation.SelectedValue), txtDesignationDesc.Text, txtDesgnationStartDate.Text, txtDesgnationEndDate.Text, txtDesignationRemark.Text, Active);
                }
                else
                {
                    JobDesignationKey = Convert.ToInt32(lblJobDesignationKey.Text);
                    AddDesignation(JobDesignationKey, Convert.ToInt16(ddlJobDesignation.SelectedValue), txtDesignationDesc.Text, txtDesgnationStartDate.Text, txtDesgnationEndDate.Text, txtDesignationRemark.Text, Active);
                    btnDesignationAdd.Text = "Add New"; //reset
                    lblJobDesignationKey.Text = "-1"; //reset
                    //UpdateDesignationTempTable(lblJobDesignationKey.Text, Convert.ToInt16(ddlJobDesignation.SelectedValue), txtDesignationDesc.Text, txtDesgnationStartDate.Text, txtDesgnationEndDate.Text, txtDesignationRemark.Text, Active);
                }
            }
        }
        tbcEntry.ActiveTab = tbpDesignation;

    }

    private void AddDesignation(int JobDesignationKey, Int16 JobDesignationCode, string JobDescriptionDetail, string dStartDate, string dEndDate, string Remark, bool Active)
    {

        EmployeeDesignationTable objEmployeeJobDesignation = new EmployeeDesignationTable();
        UserAccountTable _account = new UserAccountTable();
        _account.UserAccountKey = Convert.ToInt32(lblUserAccountKey.Text);
        objEmployeeJobDesignation.UserAccountKey = _account.UserAccountKey;
        string StartDate = dStartDate;
        var dtfi1 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy HH:mm:ss", DateSeparator = "-" };
        DateTime objStartDate = Convert.ToDateTime(StartDate, dtfi1);

        string EndDate = dEndDate;
        var dtfi2 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy HH:mm:ss", DateSeparator = "-" };
        DateTime objEndDate = Convert.ToDateTime(EndDate, dtfi2);
        objEmployeeJobDesignation.EmployeeDesignationKey = JobDesignationKey;
        objEmployeeJobDesignation.JobDesignationCode = JobDesignationCode;
        objEmployeeJobDesignation.JobDescriptionDetail = JobDescriptionDetail;
        objEmployeeJobDesignation.StartDate = objStartDate;
        objEmployeeJobDesignation.EndDate = objEndDate;
        objEmployeeJobDesignation.Active = Active;
        objEmployeeJobDesignation.Remarks = Remark;
        objEmployeeJobDesignation.Status = 1;
        objEmployeeJobDesignation.CreatedDateTime = DateTime.Now;
        objEmployeeJobDesignation.ModifiedDateTime = DateTime.Now;

        EmployeeDesignationTableManager.Save(objEmployeeJobDesignation);
        if (objEmployeeJobDesignation.EmployeeDesignationKey <= 0)
        {
            lblMessage.Text += "Saving Employee Job Designation was failed!<br/>";
        }
        else
        {
            ClearDesignationRecord();
            FillEmployeeDesignation(_account.UserAccountKey);
        }

    }

    protected void btnSalaryAdd_Click(object sender, EventArgs e)
    {
        if (txtAmount.Text.Equals(String.Empty))
        {
            lblMessage.Text = "Amount should not blank.";
        }

        else
        {
            if (txtSalaryStartDate.Text.Equals(String.Empty) || txtSalaryEndDate.Text.Equals(String.Empty))
            {

                lblMessage.Text = "Start Date,End Date should not blank.";
            }
        }
        if (!txtAmount.Text.Equals(String.Empty) && !(txtSalaryStartDate.Text.Equals(String.Empty) && txtSalaryEndDate.Text.Equals(String.Empty)))
        {

            Page.Validate("vgSalary");
            if (Page.IsValid)
            {

                bool Active = true;
                int EmployeeSalaryKey = 0;
                if (chkActive.Checked == false)
                {
                    Active = false;
                }
                if (btnSalaryAdd.Text == "Add New")
                {
                    EmployeeSalaryKey = Convert.ToInt32(-1);
                    AddSalary(EmployeeSalaryKey, Convert.ToInt16(ddlpaymentType.SelectedValue), Convert.ToInt16(ddlCurrency.SelectedValue), txtSalaryStartDate.Text, txtSalaryEndDate.Text, txtAmount.Text, txtAllotment1.Text, txtAllotment2.Text, txtSalaryRemark.Text, Active);
                    //AddToSalaryTempTable(Convert.ToInt16(ddlpaymentType.SelectedValue), Convert.ToInt16(ddlCurrency.SelectedValue), txtSalaryStartDate.Text, txtSalaryEndDate.Text, txtAmount.Text, txtAllotment1.Text, txtAllotment2.Text, txtSalaryRemark.Text, Active);
                }
                else
                {
                    EmployeeSalaryKey = Convert.ToInt32(lblSalaryKey.Text);
                    AddSalary(EmployeeSalaryKey, Convert.ToInt16(ddlpaymentType.SelectedValue), Convert.ToInt16(ddlCurrency.SelectedValue), txtSalaryStartDate.Text, txtSalaryEndDate.Text, txtAmount.Text, txtAllotment1.Text, txtAllotment2.Text, txtSalaryRemark.Text, Active);
                    btnSalaryAdd.Text = "Add New"; //reset
                    lblSalaryKey.Text = "-1"; //reset
                    //UpdateSalaryTempTable(lblSalaryKey.Text, Convert.ToInt16(ddlpaymentType.SelectedValue), Convert.ToInt16(ddlCurrency.SelectedValue), txtAmount.Text, txtAllotment1.Text, txtAllotment2.Text, txtSalaryStartDate.Text, txtSalaryEndDate.Text, txtSalaryRemark.Text, Active);
                }
            }
        }
        tbcEntry.ActiveTab = tbpSalary;

    }

    private void AddSalary(int EmployeeSalaryKey, Int16 PaymentTypeCode, Int16 CurrencyCode, string dStartDate, string dEndDate, string Amount, string Allotment1, string Allotment2, string Remark, bool Active)
    {

        EmployeeSalaryTable objEmployeeSalary = new EmployeeSalaryTable();
        UserAccountTable _account = new UserAccountTable();
        _account.UserAccountKey = Convert.ToInt32(lblUserAccountKey.Text);
        objEmployeeSalary.UserAccountKey = _account.UserAccountKey;
        string StartDate = dStartDate;
        var dtfi1 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy HH:mm:ss", DateSeparator = "-" };
        DateTime objStartDate = Convert.ToDateTime(StartDate, dtfi1);

        string EndDate = dEndDate;
        var dtfi2 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy HH:mm:ss", DateSeparator = "-" };
        DateTime objEndDate = Convert.ToDateTime(EndDate, dtfi2);
        objEmployeeSalary.EmployeeSalaryKey = EmployeeSalaryKey;
        objEmployeeSalary.CurrencyCode = CurrencyCode;
        objEmployeeSalary.PaymentTypeCode = PaymentTypeCode;
        objEmployeeSalary.StartDate = objStartDate;
        objEmployeeSalary.EndDate = objEndDate;
        objEmployeeSalary.Amount = Convert.ToDecimal(Amount);
        objEmployeeSalary.Allotment1 = Allotment1.Equals(String.Empty) ? Convert.ToDecimal(0) : Convert.ToDecimal(Allotment1); //Convert.ToDecimal(Allotment1);
        objEmployeeSalary.Allotment2 = Allotment2.Equals(String.Empty) ? Convert.ToDecimal(0) : Convert.ToDecimal(Allotment2); //Convert.ToDecimal(Allotment2);
        objEmployeeSalary.Active = Active;
        objEmployeeSalary.Remarks = Remark;
        objEmployeeSalary.Status = 1;
        objEmployeeSalary.CreatedDateTime = DateTime.Now;
        objEmployeeSalary.ModifiedDateTime = DateTime.Now;

        EmployeeSalaryTableManager.Save(objEmployeeSalary);
        if (objEmployeeSalary.EmployeeSalaryKey <= 0)
        {
            lblMessage.Text += "Saving Employee Salary was failed!<br/>";
        }
        else
        {
            ClearSalaryRecord();
            FillEmployeeSalary(_account.UserAccountKey);
        }

    }

    protected void chkPSameAsResident_CheckedChanged(object sender, EventArgs e)
    {
        divPUnitNo.Visible = !chkPSameAsResident.Checked;
        divPStreetName.Visible = !chkPSameAsResident.Checked;
        divPCountry.Visible = !chkPSameAsResident.Checked;
        divPCity.Visible = !chkPSameAsResident.Checked;

        rfvPUnitNo.Enabled = !chkPSameAsResident.Checked;
        rfvPStreetName.Enabled = !chkPSameAsResident.Checked;
        rfvPCountry.Enabled = !chkPSameAsResident.Checked;
        rfvPDistrict.Enabled = !chkPSameAsResident.Checked;
        rfvPCity.Enabled = !chkPSameAsResident.Checked;
        rfvPPostCode.Enabled = !chkPSameAsResident.Checked;

        if (chkPSameAsResident.Checked)
        {
            chkPSameAsResident.ForeColor = System.Drawing.Color.Red;
        }
        else
        {
            chkPSameAsResident.ForeColor = System.Drawing.Color.Green;
        }
    }

    protected void btnBack_Click(object sender, EventArgs e)
    {

        Response.Redirect("Employees-List.aspx");
    }

    protected void dgExperienceBrowse_RowEditing(object sender, GridViewEditEventArgs e)
    {
        dgExperienceBrowse.EditIndex = e.NewEditIndex;
        DataTable lDT = new DataTable();
        EmployeeJobExperiencesTableList _sJobExperiencesList = new EmployeeJobExperiencesTableList();
        if (Request.Params["UserAccountKey"] != null != null)
        {
            _UserAccountKey = Convert.ToInt32(Request.Params["UserAccountKey"]);
        }
        Int32 ProfileKey = _UserAccountKey;
        _sJobExperiencesList = EmployeeJobExperiencesTableManager.GetListByUserAccountKey(_UserAccountKey);
        //CreateTable(_sJobExperiencesList);
        dgExperienceBrowse.DataSource = _sJobExperiencesList;//Session["JobExperiencesDT"];
        dgExperienceBrowse.DataBind();
        lblTopMessage.Text = DateTime.Now.ToString();
        tbcEntry.ActiveTab = tbpInfo3;
    }

    protected void dgExperienceBrowse_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        dgExperienceBrowse.PageIndex = e.NewPageIndex;
        LoadEmployeeInfo(_UserAccountKey);
    }

    protected void dgExperienceBrowse_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

        int EmployeeJobExperienceKey = Convert.ToInt32(dgExperienceBrowse.DataKeys[e.RowIndex].Value);
        int UserAccountKey = Convert.ToInt32(lblUserAccountKey.Text);

        if (EmployeeJobExperiencesTableManager.Delete(EmployeeJobExperienceKey))
        {
            lblMessage.Text = "Employee Job Experience deleted";
        }
        else
        {
            lblMessage.Text = "Employee Job Experience Deleted Fail";
        }
        EmployeeJobExperiencesTableList _EmployeeQualificationList = EmployeeJobExperiencesTableManager.GetListByUserAccountKey(UserAccountKey);
      
        dgExperienceBrowse.EditIndex = -1;
        dgExperienceBrowse.DataSource = _EmployeeQualificationList;
        dgExperienceBrowse.DataBind();

    }

    protected void dgExperienceBrowse_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        Page.Validate();
        if (Page.IsValid)
        {
            int EmployeeJobExperienceKey = Convert.ToInt32(dgExperienceBrowse.DataKeys[e.RowIndex].Value);
            //int UserAccountKey = Convert.ToInt32(dgExperienceBrowse.Rows[e.RowIndex].Cells[1].Text);
            TextBox txtPreviousEmployer = (TextBox)dgExperienceBrowse.Rows[e.RowIndex].FindControl("txtPreviousEmployer1");
            TextBox txtStartDate = (TextBox)dgExperienceBrowse.Rows[e.RowIndex].FindControl("txtStartDate1");
            var dtfi1 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy HH:mm:ss", DateSeparator = "-" };
            DateTime objStartDate = Convert.ToDateTime(txtStartDate.Text, dtfi1);
            TextBox txtEndDate = (TextBox)dgExperienceBrowse.Rows[e.RowIndex].FindControl("txtEndDate1");
            var dtfi2 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy HH:mm:ss", DateSeparator = "-" };
            DateTime objEndDate = Convert.ToDateTime(txtEndDate.Text, dtfi1);
            TextBox txtPosition = (TextBox)dgExperienceBrowse.Rows[e.RowIndex].FindControl("txtPosition1");
            TextBox txtBasicSalary = (TextBox)dgExperienceBrowse.Rows[e.RowIndex].FindControl("txtBasicSalary1");
            TextBox txtDescription = (TextBox)dgExperienceBrowse.Rows[e.RowIndex].FindControl("txtDescription1");
            DataTable lDT = new DataTable();
            lDT = (DataTable)Session["JobExperiencesDT"];
            foreach (DataRow lDR in lDT.Rows)
            {
                if (EmployeeJobExperienceKey == Convert.ToInt32(lDR["EmployeeJobExperienceKey"]))
                {
                    lDR["PreviousEmployer"] = txtPreviousEmployer.Text;
                    lDR["StartDate"] = objStartDate;
                    lDR["EndDate"] = objEndDate;
                    lDR["Position"] = txtPosition.Text;
                    lDR["BasicSalary"] = Convert.ToDouble(txtBasicSalary.Text);
                    lDR["Remarks"] = txtDescription.Text;
                    lDR["Status"] = "Edit";

                }
            }
            lDT.AcceptChanges();
            dgExperienceBrowse.EditIndex = -1;
            dgExperienceBrowse.DataSource = lDT;
            dgExperienceBrowse.DataBind();


        }


    }

    protected void dgExperienceBrowse_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        if (Request.Params["UserAccountKey"] != null != null)
        {
            _UserAccountKey = Convert.ToInt32(Request.Params["UserAccountKey"]);
        }

        dgExperienceBrowse.EditIndex = -1;

        LoadEmployeeInfo(_UserAccountKey);

    }

    protected void dgExperienceBrowse_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label Status = (Label)e.Row.FindControl("lblStatus");
            if (Status.Text == "Delete")
            {
                e.Row.Visible = false;
            }

        }
    }

    protected void dgExperienceBrowse_SelectedIndexChanged(object sender, EventArgs e)
    {
        ClearJobExperienceRecord();
        btnAdd.Text = "Update";
        tbcEntry.ActiveTab = tbpInfo3;
        if (dgExperienceBrowse.SelectedIndex >= 0)
        {
            DataKey _selectedDataKey = dgExperienceBrowse.SelectedDataKey;
            int _EmployeeJobExperienceKey = Convert.ToInt32(_selectedDataKey[0]);
            //int _UserAccountKey = Convert.ToInt32(_selectedDataKey[1]);

            if (_EmployeeJobExperienceKey > 0)
            {
                GridViewRow _selectedRow = dgExperienceBrowse.SelectedRow;

                LinkButton lnkEdit = (LinkButton)_selectedRow.FindControl("lnkbtnEdit");
                lnkEdit.Enabled = false;

                LinkButton lnkDelete = (LinkButton)_selectedRow.FindControl("lnkbtnDelete");
                lnkDelete.Enabled = false;

                EmployeeJobExperiencesTable _jobExperience = EmployeeJobExperiencesTableManager.GetItem(_EmployeeJobExperienceKey);
                lblJobExperienceKey.Text = Convert.ToString(_jobExperience.EmployeeJobExperienceKey);
                lblAccountKey.Text = Convert.ToString(_jobExperience.UserAccountKey);
                txtPreviousEmployer.Text = Convert.ToString(_jobExperience.PreviousEmployer);
                DateTime startDate = Convert.ToDateTime(_jobExperience.StartDate);
                txtStartDate.Text = startDate.ToString("dd/MM/yyyy");
                DateTime EndDate = Convert.ToDateTime(_jobExperience.EndDate);
                txtEndDate.Text = EndDate.ToString("dd/MM/yyyy");
                txtPosition.Text = Convert.ToString(_jobExperience.Position);
                txtSalary.Text = Convert.ToDecimal(_jobExperience.BasicSalary).ToString("0.00");
                txtRefereeName.Text = Convert.ToString(_jobExperience.RefereeName) == null ? string.Empty : Convert.ToString(_jobExperience.RefereeName);
                txtRefereeAddress.Text = Convert.ToString(_jobExperience.RefereeAddress) == null ? string.Empty : Convert.ToString(_jobExperience.RefereeAddress);
                txtRefereeContact.Text = Convert.ToString(_jobExperience.RefereeContact) == null ? string.Empty : Convert.ToString(_jobExperience.RefereeContact);
                txtRefereeEmail.Text = Convert.ToString(_jobExperience.RefereeEmail) == null ? string.Empty : Convert.ToString(_jobExperience.RefereeEmail);
                txtRemarks.Text = Convert.ToString(_jobExperience.Remarks);                

            }
        }
    }

    protected void dgvEmployeeQualtification_SelectedIndexChanged(object sender, EventArgs e)
    {
        ClearQualificationRecord();
        btnQualifyAdd.Text = "Update";
        tbcEntry.ActiveTab = tbpInfo4;
        if (dgvEmployeeQualtification.SelectedIndex >= 0)
        {
            DataKey _selectedDataKey = dgvEmployeeQualtification.SelectedDataKey;
            int _EmployeeJobQualificationKey = Convert.ToInt32(_selectedDataKey[0]);
            //int _UserAccountKey = Convert.ToInt32(_selectedDataKey[1]);

            if (_EmployeeJobQualificationKey > 0)
            {
                GridViewRow _selectedRow = dgvEmployeeQualtification.SelectedRow;

                LinkButton lnkEdit = (LinkButton)_selectedRow.FindControl("lnkbtnEdit");
                lnkEdit.Enabled = false;

                LinkButton lnkDelete = (LinkButton)_selectedRow.FindControl("lnkbtnDelete");
                lnkDelete.Enabled = false;

                EmployeeQualtificationTable _EmployeeQualification = EmployeeQualtificationTableManager.GetItem(_EmployeeJobQualificationKey);
                lblQualificationKey.Text = Convert.ToString(_EmployeeQualification.EmployeeQualtificationKey);
                lblAccountKey.Text = Convert.ToString(_EmployeeQualification.UserAccountKey);
                txtQualification2.Text = Convert.ToString(_EmployeeQualification.QualificationName);
                txtOrganization.Text = Convert.ToString(_EmployeeQualification.Organization);
                txtYear.Text = Convert.ToString(_EmployeeQualification.Year);
                txtGradelevel.Text = Convert.ToString(_EmployeeQualification.GradeLevel);
                txtQualifyOthers.Text = Convert.ToString(_EmployeeQualification.Others);


                //DataTable lDT = new DataTable();
                //lDT = (DataTable)Session["QualificationDT"];
                //foreach (DataRow lDR in lDT.Rows)
                //{
                //    if (Convert.ToInt32(lDR["EmployeeQualtificationKey"]) == _EmployeeJobQualificationKey)
                //    {
                //        lblQualificationKey.Text = Convert.ToString(lDR["EmployeeQualtificationKey"]);
                //        lblAccountKey.Text = Convert.ToString(lDR["UserAccountKey"]);
                //        txtQualification2.Text = Convert.ToString(lDR["QualificationName"]);
                //        txtOrganization.Text = Convert.ToString(lDR["Organization"]);
                //        txtYear.Text = Convert.ToString(lDR["Year"]);
                //        txtGradelevel.Text = Convert.ToString(lDR["GradeLevel"]);
                //        txtQualifyOthers.Text = Convert.ToString(lDR["Others"]);
                //    }
                //}

            }
        }
    }

    protected void dgvEmployeeQualtification_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

        int EmployeeQualificationKey = Convert.ToInt32(dgvEmployeeQualtification.DataKeys[e.RowIndex].Value);
        int UserAccountKey = Convert.ToInt32(lblUserAccountKey.Text);

        if (EmployeeQualtificationTableManager.Delete(EmployeeQualificationKey))
        {
            lblMessage.Text = "Employee Qualification deleted";
        }
        else
        {
            lblMessage.Text = "Employee Qualification Deleted Fail";
        }

        
        EmployeeQualtificationTableList _EmployeeQualificationList = EmployeeQualtificationTableManager.GetList(UserAccountKey);
        dgvEmployeeQualtification.EditIndex = -1;
        dgvEmployeeQualtification.DataSource = _EmployeeQualificationList;
        dgvEmployeeQualtification.DataBind();
        tbcEntry.ActiveTab = tbpInfo4;

    }

    protected void dgvEmployeeQualtification_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label Status = (Label)e.Row.FindControl("lblStatus");
            if (Status.Text == "Delete")
            {
                e.Row.Visible = false;
            }

        }
    }

    protected void gvEmployeeOtherSkills_SelectedIndexChanged(object sender, EventArgs e)
    {
        ClearOtherSkillRecord();
        btnSkillAdd.Text = "Update";
        tbcEntry.ActiveTab = tbpInfo5;
        if (gvEmployeeOtherSkills.SelectedIndex >= 0)
        {
            DataKey _selectedDataKey = gvEmployeeOtherSkills.SelectedDataKey;
            int _EmployeeOtherSkillsKey = Convert.ToInt32(_selectedDataKey[0]);
            //int _UserAccountKey = Convert.ToInt32(_selectedDataKey[1]);

            if (_EmployeeOtherSkillsKey > 0)
            {
                GridViewRow _selectedRow = gvEmployeeOtherSkills.SelectedRow;

                LinkButton lnkEdit = (LinkButton)_selectedRow.FindControl("lnkbtnEdit");
                lnkEdit.Enabled = false;

                LinkButton lnkDelete = (LinkButton)_selectedRow.FindControl("lnkbtnDelete");
                lnkDelete.Enabled = false;

                EmployeeOtherSkillsTable _EmployeeOtherSkill = EmployeeOtherSkillsTableManager.GetItem(_EmployeeOtherSkillsKey);
                lblSkillKey.Text = Convert.ToString(_EmployeeOtherSkill.EmployeeOtherSkillsKey);
                lblAccountKey.Text = Convert.ToString(_EmployeeOtherSkill.UserAccountKey);
                txtSkill.Text = Convert.ToString(_EmployeeOtherSkill.SkillName);
                txtSkillOrganization.Text = Convert.ToString(_EmployeeOtherSkill.Organization);
                txtNoOfYear.Text = Convert.ToString(_EmployeeOtherSkill.NoOfYear);
                txtSkillLevel.Text = Convert.ToString(_EmployeeOtherSkill.SkillLevel);
                txtSkillOthers.Text = Convert.ToString(_EmployeeOtherSkill.Others);

                
            }
        }
    }

    protected void gvEmployeeOtherSkills_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

        int EmployeeOtherSkillsKey = Convert.ToInt32(gvEmployeeOtherSkills.DataKeys[e.RowIndex].Value);
        int UserAccountKey = Convert.ToInt32(lblUserAccountKey.Text);

        if (EmployeeOtherSkillsTableManager.Delete(EmployeeOtherSkillsKey))
        {
            lblMessage.Text = "Employee Other Skill deleted";
        }
        else
        {
            lblMessage.Text = "Employee Ohter Skill Deleted Fail";
        }
        
        EmployeeOtherSkillsTableList _sEmployeeOtherSkillList = EmployeeOtherSkillsTableManager.GetList(UserAccountKey);
        gvEmployeeOtherSkills.EditIndex = -1;
        gvEmployeeOtherSkills.DataSource = _sEmployeeOtherSkillList;
        gvEmployeeOtherSkills.DataBind();
        tbcEntry.ActiveTab = tbpInfo5;

    }

    protected void gvEmployeeOtherSkills_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label Status = (Label)e.Row.FindControl("lblStatus");
            if (Status.Text == "Delete")
            {
                e.Row.Visible = false;
            }

        }
    }

    protected void gvDesignation_SelectedIndexChanged(object sender, EventArgs e)
    {
        ClearDesignationRecord();
        btnDesignationAdd.Text = "Update";
        tbcEntry.ActiveTab = tbpDesignation;
        if (gvDesignation.SelectedIndex >= 0)
        {
            DataKey _selectedDataKey = gvDesignation.SelectedDataKey;
            int _EmployeeDesignationKey = Convert.ToInt32(_selectedDataKey[0]);
            //int _UserAccountKey = Convert.ToInt32(_selectedDataKey[1]);

            if (_EmployeeDesignationKey > 0)
            {
                GridViewRow _selectedRow = gvDesignation.SelectedRow;

                LinkButton lnkEdit = (LinkButton)_selectedRow.FindControl("lnkbtnEdit");
                lnkEdit.Enabled = false;

                LinkButton lnkDelete = (LinkButton)_selectedRow.FindControl("lnkbtnDelete");
                lnkDelete.Enabled = false;

                EmployeeDesignationTable _EmployeeDesignation = EmployeeDesignationTableManager.GetItem(_EmployeeDesignationKey);

                lblJobDesignationKey.Text = Convert.ToString(_EmployeeDesignation.EmployeeDesignationKey);
                lblAccountKey.Text = Convert.ToString(_EmployeeDesignation.UserAccountKey);
                ddlJobDesignation.SelectedValue = Convert.ToString(_EmployeeDesignation.JobDesignationCode);
                txtDesignationDesc.Text = Convert.ToString(_EmployeeDesignation.JobDescriptionDetail);
                DateTime startDate = Convert.ToDateTime(_EmployeeDesignation.StartDate);
                txtDesgnationStartDate.Text = startDate.ToString("dd/MM/yyyy");
                DateTime EndDate = Convert.ToDateTime(_EmployeeDesignation.EndDate);
                txtDesgnationEndDate.Text = EndDate.ToString("dd/MM/yyyy");
                txtDesignationRemark.Text = Convert.ToString(_EmployeeDesignation.Remarks);
                chkDesignation.Checked = Convert.ToBoolean(_EmployeeDesignation.Active);

                

            }
        }
    }

    protected void gvDesignation_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

        int EmployeeDesignationKey = Convert.ToInt32(gvDesignation.DataKeys[e.RowIndex].Value);
        int UserAccountKey = Convert.ToInt32(lblUserAccountKey.Text);

        if (EmployeeDesignationTableManager.Delete(EmployeeDesignationKey))
        {
            lblMessage.Text = "Employee Other Skill deleted";
        }
        else
        {
            lblMessage.Text = "Employee Ohter Skill Deleted Fail";
        }
        //DataTable lDT = new DataTable();
        //lDT = (DataTable)Session["EmployeeDesignationsDT"];
        //foreach (DataRow lDR in lDT.Rows)
        //{
        //    if (EmployeeDesignationKey == Convert.ToInt32(lDR["EmployeeDesignationKey"]))
        //    {
        //        lDR["Status"] = "Delete";
        //    }
        //}
        //lDT.AcceptChanges();
        EmployeeDesignationTableList _sEmployeeDesignationList = EmployeeDesignationTableManager.GetList(UserAccountKey);
        gvDesignation.EditIndex = -1;
        gvDesignation.DataSource = _sEmployeeDesignationList;
        gvDesignation.DataBind();
        tbcEntry.ActiveTab = tbpDesignation;

    }

    protected void gvDesignation_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label Status = (Label)e.Row.FindControl("lblStatus");
            if (Status.Text == "Delete")
            {
                e.Row.Visible = false;
            }

        }
    }

    protected void gvSalary_SelectedIndexChanged(object sender, EventArgs e)
    {
        ClearSalaryRecord();
        btnSalaryAdd.Text = "Update";
        tbcEntry.ActiveTab = tbpSalary;
        if (gvSalary.SelectedIndex >= 0)
        {
            DataKey _selectedDataKey = gvSalary.SelectedDataKey;
            int _EmployeeSalaryKey = Convert.ToInt32(_selectedDataKey[0]);

            if (_EmployeeSalaryKey > 0)
            {
                GridViewRow _selectedRow = gvSalary.SelectedRow;

                LinkButton lnkEdit = (LinkButton)_selectedRow.FindControl("lnkbtnEdit");
                lnkEdit.Enabled = false;

                LinkButton lnkDelete = (LinkButton)_selectedRow.FindControl("lnkbtnDelete");
                lnkDelete.Enabled = false;

                EmployeeSalaryTable _EmployeeSalary = EmployeeSalaryTableManager.GetItem(_EmployeeSalaryKey);
                lblSalaryKey.Text = Convert.ToString(_EmployeeSalary.EmployeeSalaryKey);
                lblAccountKey.Text = Convert.ToString(_EmployeeSalary.UserAccountKey);
                ddlpaymentType.SelectedValue = Convert.ToString(_EmployeeSalary.PaymentTypeCode);
                DateTime startDate = Convert.ToDateTime(_EmployeeSalary.StartDate);
                txtSalaryStartDate.Text = startDate.ToString("dd/MM/yyyy");
                DateTime EndDate = Convert.ToDateTime(_EmployeeSalary.EndDate);
                txtSalaryEndDate.Text = EndDate.ToString("dd/MM/yyyy");
                txtAmount.Text = Convert.ToDecimal(_EmployeeSalary.Amount) == 0 ? string.Empty : Convert.ToDecimal(_EmployeeSalary.Amount).ToString("0.00");
                txtAllotment1.Text = Convert.ToDecimal(_EmployeeSalary.Allotment1) == 0 ? string.Empty : Convert.ToDecimal(_EmployeeSalary.Allotment1).ToString("0.00");
                txtAllotment2.Text = Convert.ToDecimal(_EmployeeSalary.Allotment2) == 0 ? string.Empty : Convert.ToDecimal(_EmployeeSalary.Allotment2).ToString("0.00");//Convert.ToDecimal(lDR["Allotment2"]).ToString("0.00");
                txtSalaryRemark.Text = Convert.ToString(_EmployeeSalary.Remarks);
                chkActive.Checked = Convert.ToBoolean(_EmployeeSalary.Active);

                //DataTable lDT = new DataTable();
                //lDT = (DataTable)Session["EmployeeSalaryDT"];
                //foreach (DataRow lDR in lDT.Rows)
                //{
                //    if (Convert.ToInt32(lDR["EmployeeSalaryKey"]) == _EmployeeSalaryKey)
                //    {

                //    }
                //}

            }
        }
    }

    protected void gvSalary_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

        int EmployeeSalaryKey = Convert.ToInt32(gvSalary.DataKeys[e.RowIndex].Value);

        int UserAccountKey = Convert.ToInt32(lblUserAccountKey.Text);

        if (EmployeeSalaryTableManager.Delete(EmployeeSalaryKey))
        {
            lblMessage.Text = "Employee Salary deleted";
        }
        else
        {
            lblMessage.Text = "Employee Salary Deleted Fail";
        }

        EmployeeSalaryTransTableList _sEmployeeSalaryList = EmployeeSalaryTransTableManager.GetList(UserAccountKey);
        
        gvSalary.EditIndex = -1;
        gvSalary.DataSource = _sEmployeeSalaryList;
        gvSalary.DataBind();
        tbcEntry.ActiveTab = tbpSalary;

    }

    protected void gvSalary_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label Status = (Label)e.Row.FindControl("lblStatus");
            if (Status.Text == "Delete")
            {
                e.Row.Visible = false;
            }

        }
        tbcEntry.ActiveTab = tbpSalary;
    }

    protected void btnUpdatePhoto_Click(object sender, EventArgs e)
    {
        Response.Redirect("Photo-Upload.aspx?id=" + lblUserAccountKey.Text);
    }

    #endregion

    #region "Methods   
     

    private void ClearJobExperienceRecord()
    {
        txtPreviousEmployer.Text = string.Empty;
        txtStartDate.Text = string.Empty;
        txtEndDate.Text = string.Empty;
        txtPosition.Text = string.Empty;
        txtSalary.Text = string.Empty;
        txtRemarks.Text = string.Empty;
        txtRefereeName.Text = string.Empty;
        txtRefereeAddress.Text = string.Empty;
        txtRefereeContact.Text = string.Empty;
        txtRefereeEmail.Text = string.Empty;
    }

    private void UpdateTempTable(string EmployeeJobExperienceKey, string UserAccountKeyString, string PreviousEmployer, string dStartDate, string dEndDate, string Position, decimal BasicSalary, string RefereeName, string RefereeAddress, string RefereeEmail, string RefereeContact, string Remarks)
    {
        int JobExperienceKey = Convert.ToInt32(EmployeeJobExperienceKey);
        int UserAccountKey = Convert.ToInt32(UserAccountKeyString);
        //TextBox txtPreviousEmployer = (TextBox)dgExperienceBrowse.Rows[e.RowIndex].FindControl("txtPreviousEmployer1");
        string txtStartDate = dStartDate;
        var dtfi1 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy HH:mm:ss", DateSeparator = "-" };
        DateTime objStartDate = Convert.ToDateTime(txtStartDate, dtfi1);
        string txtEndDate = dEndDate;
        var dtfi2 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy HH:mm:ss", DateSeparator = "-" };
        DateTime objEndDate = Convert.ToDateTime(txtEndDate, dtfi1);
        DataTable lDT = new DataTable();
        lDT = (DataTable)Session["JobExperiencesDT"];
        foreach (DataRow lDR in lDT.Rows)
        {
            if (JobExperienceKey == Convert.ToInt32(lDR["EmployeeJobExperienceKey"]))
            {
                lDR["PreviousEmployer"] = txtPreviousEmployer.Text;
                lDR["StartDate"] = objStartDate;
                lDR["EndDate"] = objEndDate;
                lDR["Position"] = Position;
                lDR["BasicSalary"] = BasicSalary.Equals(string.Empty) ? 0 : Convert.ToDecimal(BasicSalary);
                lDR["RefereeName"] = Convert.ToString(RefereeName);
                lDR["RefereeAddress"] = Convert.ToString(RefereeAddress);
                lDR["RefereeEmail"] = Convert.ToString(RefereeEmail);
                lDR["RefereeContact"] = Convert.ToString(RefereeContact);
                lDR["Remarks"] = Remarks;
                lDR["Status"] = "Edit";

            }
        }
        lDT.AcceptChanges();
        dgExperienceBrowse.EditIndex = -1;
        dgExperienceBrowse.DataSource = lDT;
        dgExperienceBrowse.DataBind();
        ClearJobExperienceRecord();
        btnAdd.Text = "Add New";
    }

    private void AddToTempTable(String PreviousEmployer, string dStartDate, string dEndDate, string Position, string BasicSalary, string RefereeName, string RefereeAddress, string RefereeEmail, string RefereeContact, string Remarks)
    {

        DataTable lDT = new DataTable();
        lDT = (DataTable)Session["JobExperiencesDT"];
        int count = lDT.Rows.Count;

        DataRow dataRow = lDT.NewRow();
        dataRow["EmployeeJobExperienceKey"] = count + 1;
        dataRow["UserAccountKey"] = 0;
        dataRow["PreviousEmployer"] = PreviousEmployer;
        string StartDate = dStartDate;
        var dtfi1 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy HH:mm:ss", DateSeparator = "-" };
        DateTime objStartDate = Convert.ToDateTime(StartDate, dtfi1);
        dataRow["StartDate"] = objStartDate;
        string EndDate = dEndDate;
        var dtfi2 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy HH:mm:ss", DateSeparator = "-" };
        DateTime objEndDate = Convert.ToDateTime(EndDate, dtfi2);
        dataRow["EndDate"] = objEndDate;
        dataRow["Position"] = Position;
        dataRow["BasicSalary"] = BasicSalary.Equals(string.Empty) ? 0 : Convert.ToDecimal(BasicSalary);
        dataRow["RefereeName"] = RefereeName;
        dataRow["RefereeAddress"] = RefereeAddress;
        dataRow["RefereeEmail"] = RefereeEmail;
        dataRow["RefereeContact"] = RefereeContact;
        dataRow["Remarks"] = Remarks;
        dataRow["Status"] = "New";
        lDT.Rows.Add(dataRow);
        Session["JobExperiencesDT"] = lDT;
        lDT.AcceptChanges();
        dgExperienceBrowse.EditIndex = -1;
        dgExperienceBrowse.DataSource = lDT;
        dgExperienceBrowse.DataBind();
        ClearJobExperienceRecord();

    }

    protected void EmployeeContactNumbers_ServerSideValidate(object source, ServerValidateEventArgs args)
    {
        bool _retValue = true;


        args.IsValid = _retValue;
    }

    protected void EmployeeDOB_ServerSideValidation(object source, ServerValidateEventArgs args)
    {
        //bool _retValue = true;        
        //string _strDOB = string.Empty;

        //if (ddlDOBDay.SelectedValue == "-1" || ddlDOBMonth.SelectedValue == "-1" || ddlDOBYear.SelectedValue == "-1")
        //{
        //    _retValue = false;
        //}
        //args.IsValid = _retValue;
        bool _retValue = true;
        DateTime _dtDOB = DateTime.Now;
        string _strDOB = string.Empty;

        if (ddlDOBDay.Text != "-1" && ddlDOBMonth.Text != "-1" && ddlDOBYear.Text != "-1")
        {
            _strDOB = ddlDOBDay.Text + "/" + ddlDOBMonth.SelectedItem.Text + "/" + ddlDOBYear.Text.ToString();
            if (!SIS.Utilities.General.GetDateTime(_strDOB, out _dtDOB))
            {

                lblMessage.Text += _strDOB + "  " + " Family Memeber's DOB is invalid!<br/>";
                _retValue = false;
            }
            else
            {
                _retValue = true;                 
            }
        }
        else
        {
            lblMessage.Text += "Select Valid Employee DOB.<br/>";
            _retValue = false;
        }
        args.IsValid = _retValue;
    }

    protected void JobExperienceEndDate_ServerSideValidation(object source, ServerValidateEventArgs args)
    {

        bool _retValue = true;
        string StartDate = txtStartDate.Text;
        var dtfi1 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy", DateSeparator = "/" };
        DateTime objStartDate = Convert.ToDateTime(StartDate, dtfi1);
        string EndDate = txtEndDate.Text;
        var dtfi2 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy", DateSeparator = "/" };
        DateTime objEndDate = Convert.ToDateTime(EndDate, dtfi2);

        //DateTime _dEnd = DateTime.Parse(txtEndDate.Text);
        string _strDOB = string.Empty;

        if (!txtEndDate.Text.Equals(string.Empty))
        {
            if (txtStartDate.Text.Equals(string.Empty))
            {
                _retValue = false;
            }
            else if (objStartDate > objEndDate)
            {
                _retValue = false;
            }
        }

        args.IsValid = _retValue;
    }

    protected void DesignationEndDate_ServerSideValidation(object source, ServerValidateEventArgs args)
    {

        bool _retValue = true;
        string StartDate = txtDesgnationStartDate.Text;
        var dtfi1 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy", DateSeparator = "/" };
        DateTime objStartDate = Convert.ToDateTime(StartDate, dtfi1);
        string EndDate = txtDesgnationEndDate.Text;
        var dtfi2 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy", DateSeparator = "/" };
        DateTime objEndDate = Convert.ToDateTime(EndDate, dtfi2);

        //DateTime _dEnd = DateTime.Parse(txtEndDate.Text);
        string _strDOB = string.Empty;

        if (!txtDesgnationEndDate.Text.Equals(string.Empty))
        {
            if (txtDesgnationStartDate.Text.Equals(string.Empty))
            {
                _retValue = false;
            }
            else if (objStartDate > objEndDate)
            {
                _retValue = false;
            }
        }

        args.IsValid = _retValue;
    }

    protected void SalaryEndDate_ServerSideValidation(object source, ServerValidateEventArgs args)
    {

        bool _retValue = true;
        string StartDate = txtSalaryStartDate.Text;
        var dtfi1 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy", DateSeparator = "/" };
        DateTime objStartDate = Convert.ToDateTime(StartDate, dtfi1);
        string EndDate = txtSalaryEndDate.Text;
        var dtfi2 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy", DateSeparator = "/" };
        DateTime objEndDate = Convert.ToDateTime(EndDate, dtfi2);

        //DateTime _dEnd = DateTime.Parse(txtEndDate.Text);
        string _strDOB = string.Empty;

        if (!txtSalaryEndDate.Text.Equals(string.Empty))
        {
            if (txtSalaryStartDate.Text.Equals(string.Empty))
            {
                _retValue = false;
            }
            else if (objStartDate > objEndDate)
            {
                _retValue = false;
            }
        }

        args.IsValid = _retValue;
    }

    private void LoadEmployeeInfo(int AccountID)
    {
        UserAccountTable _account = new UserAccountTable();
        _account = UserAccountTableManager.GetItem(AccountID);

        btnUpdatePhoto.Visible = false;

        if (_account == null)
        {
            lblTopMessage.Text = "Employee account ID (" + AccountID.ToString() + ") is not found!";
        }
        else if (_account.UserAccountKey <= 0)
        {
            lblTopMessage.Text = "Employee account ID is not found!";
        }

        if (_account != null && _account.UserAccountKey > 0)
        {
            if (_account.UserAccountTypeCode != 800)
            {
                lblTopMessage.Text = "Only for Employee account ID will be loaded.";
                return;
            }

            lblUserAccountKey.Text = _account.UserAccountKey.ToString();

            EmployeeProfileTable _sprofile = new EmployeeProfileTable();
            EmployeeAddressTable _sraddress = new EmployeeAddressTable();
            EmployeeAddressTable _spaddress = new EmployeeAddressTable();
            EmployeeJobExperiencesTableList _sJobExperiencesList = new EmployeeJobExperiencesTableList();
            EmployeeDesignationTableList _sEmployeeDesignationList = new EmployeeDesignationTableList();
            EmployeeSalaryTableList _sEmployeeSalaryList = new EmployeeSalaryTableList();
            EmployeeQualtificationTableList _sQualificationList = new EmployeeQualtificationTableList();
            EmployeeOtherSkillsTableList _sSkillList = new EmployeeOtherSkillsTableList();
            EmployeeContactTable _scontact = new EmployeeContactTable();

            _sprofile = EmployeeProfileTableManager.GetItemByUserAccountKey(AccountID, _account.SchoolKey);
            if (_sprofile != null && _sprofile.EmployeeProfileKey > 0)
            {
                lblEmployeeProfileKey.Text = _sprofile.EmployeeProfileKey.ToString();
                txtFirstName.Text = _sprofile.FirstName;
                txtLastName.Text = _sprofile.LastName;
                txtOtherName.Text = _sprofile.OtherName;
                ddlGender.SelectedValue = _sprofile.Gender;
                DateTime _dtDOB = _sprofile.DateOfBirth;
                ddlDOBDay.Text = _dtDOB.Day.ToString("00");
                ddlDOBMonth.Text = _dtDOB.Month.ToString("00");
                ddlDOBYear.Text = _dtDOB.Year.ToString("0000");

                txtNRICNumber.Text = _sprofile.NRICNumber;
                ddlDrivingLicenceType.Text = _sprofile.DrivingLicenceType.ToString();
                txtDrivingLicenceNumber.Text = _sprofile.DrivingLicenseNumber;

                ddlTravelDocType.Text = _sprofile.TravelDocumentType.ToString();
                txtTravelDocNumber.Text = _sprofile.TravelDocumentNumber;

                ddlBloodGroup.Text = _sprofile.BloodGroupCode.ToString();
                ddlMaritalStatus.Text = _sprofile.MartialStatusCode.ToString();
                ddlRaceCode.Text = _sprofile.RaceCode.ToString();
                ddlReligion.Text = _sprofile.ReligionCode.ToString();
                ddlNationality.Text = _sprofile.NationalityCode.ToString();
                txtWebsiteUrl.Text = _sprofile.WebSiteUrl;
                txtHobby.Text = _sprofile.Hobby;
                ddlParentStatus.SelectedValue = _sprofile.ParentStatus.ToString();
                txtPlaceOfBirth.Text = _sprofile.PlaceOfBirth;
                DateTime SignInDate = Convert.ToDateTime(_sprofile.JoinDate);
                txtJoinDate.Text = SignInDate.ToString("dd/MM/yyyy");

                if (_sprofile.Photo != null && _sprofile.Photo.Length > 0)
                {
                    divEmployeePhoto.Visible = true;
                    imgCurrentEmployeePhoto.ImageUrl = "~/images/imagehandler.ashx?key=" + lblEmployeeProfileKey.Text + "&type=Employeephoto";
                    hplCurrentEmployeePhoto.NavigateUrl = imgCurrentEmployeePhoto.ImageUrl;
                    imgCurrentEmployeePhoto.Width = 75;
                    imgCurrentEmployeePhoto.Height = 100;
                }
                else
                {
                    divEmployeePhoto.Visible = false;
                    imgCurrentEmployeePhoto.ImageUrl = "";
                    hplCurrentEmployeePhoto.NavigateUrl = "";
                    imgCurrentEmployeePhoto.Width = 0;
                    imgCurrentEmployeePhoto.Height = 0;
                }
                btnUpdatePhoto.Visible = true;
            }

            //Contact Table

            _scontact = EmployeeContactTableManager.GetItemByUserAccountKey(AccountID);

            if (_scontact != null && _scontact.EmployeeContactKey > 0)
            {
                lblEmployeeContactKey.Text = _scontact.EmployeeContactKey.ToString();
                txtMobileNumber.Text = _scontact.MobileNumber;
                txtHomePhoneNumber.Text = _scontact.HomePhoneNumber;
                txtOtherContactNumber.Text = _scontact.OtherNumber;
                txtOfficeNumber.Text = _scontact.OfficePhoneNumber;
                txtFaxNumber.Text = _scontact.FaxNumber;
                txtEmailAddress.Text = _scontact.EmailAddress;
            }
            //Resident
            _sraddress = EmployeeAddressTableManager.GetItemByUserAccountKey(AccountID, 1);
            if (_sraddress != null && _sraddress.EmployeeAddressKey > 0)
            {
                lblEmployeeRAddressKey.Text = _sraddress.EmployeeAddressKey.ToString();
                txtUnitNo.Text = _sraddress.UnitNo;
                txtStreetName.Text = _sraddress.StreetName;
                ddlCountry.SelectedValue = _sraddress.CountryCode.ToString();
                _common.LoadDistrictCodeDDL(ddlDistrict, Convert.ToInt16(ddlCountry.SelectedItem.Value), string.Empty);
                ddlDistrict.SelectedValue = _sraddress.DistrictCode.ToString();
                _common.LoadCityCodeDDL(ddlCity, Convert.ToInt32(ddlDistrict.SelectedValue), Convert.ToInt16(ddlCountry.SelectedValue), string.Empty);
                ddlCity.SelectedValue = _sraddress.CityCode.ToString();
                txtPostCode.Text = _sraddress.PostalCode;
            }

            //Permanent/Contact
            _spaddress = EmployeeAddressTableManager.GetItemByUserAccountKey(AccountID, 2);
            if (_spaddress != null && _spaddress.EmployeeAddressKey > 0)
            {
                lblEmployeePAddressKey.Text = _spaddress.EmployeeAddressKey.ToString();
                txtPUnitNo.Text = _spaddress.UnitNo;
                txtPStreetName.Text = _spaddress.StreetName;
                ddlPCountry.SelectedValue = _spaddress.CountryCode.ToString();
                _common.LoadDistrictCodeDDL(ddlPDistrict, Convert.ToInt16(ddlPCountry.SelectedItem.Value), string.Empty);
                ddlPDistrict.SelectedValue = _spaddress.DistrictCode.ToString();
                _common.LoadCityCodeDDL(ddlPCity, Convert.ToInt32(ddlPDistrict.SelectedValue), Convert.ToInt16(ddlCountry.SelectedValue), string.Empty);
                ddlPCity.SelectedValue = _spaddress.CityCode.ToString();
                txtPPostCode.Text = _spaddress.PostalCode;
                //chkPSameAsResident.Checked = _spaddress.SameAsResident;
                chkPSameAsResident_CheckedChanged(null, null);
            }


            //Job Experiences
            DataTable lDT = new DataTable();
            _sJobExperiencesList = new EmployeeJobExperiencesTableList();
            Int32 ProfileKey = _sprofile.EmployeeProfileKey;
            _sJobExperiencesList = EmployeeJobExperiencesTableManager.GetListByUserAccountKey(AccountID);
            //CreateTable(_sJobExperiencesList);
            dgExperienceBrowse.DataSource = _sJobExperiencesList;//Session["JobExperiencesDT"];
            dgExperienceBrowse.DataBind();


            //Designation
            DataTable lDesignationDT = new DataTable();
            _sEmployeeDesignationList = new EmployeeDesignationTableList();
            _sEmployeeDesignationList = EmployeeDesignationTableManager.GetList(AccountID);
            //CreateDesignationTable(_sEmployeeDesignationList);
            gvDesignation.DataSource = _sEmployeeDesignationList;//Session["EmployeeDesignationsDT"];
            gvDesignation.DataBind();

            //Salary
            DataTable lSalaryDT = new DataTable();
            _sEmployeeSalaryList = new EmployeeSalaryTableList();
            _sEmployeeSalaryList = EmployeeSalaryTableManager.GetList(AccountID);
            //CreateSalaryTable(_sEmployeeSalaryList);
            gvSalary.DataSource = _sEmployeeSalaryList;//Session["EmployeeSalaryDT"];
            gvSalary.DataBind();

            //Designation
            DataTable lQualificationDT = new DataTable();
            _sQualificationList = new EmployeeQualtificationTableList();
            _sQualificationList = EmployeeQualtificationTableManager.GetList(AccountID);
            //CreateQualifyTable(_sQualificationList);
            dgvEmployeeQualtification.DataSource = _sQualificationList;//Session["QualificationDT"];
            dgvEmployeeQualtification.DataBind();

            //Designation
            DataTable lSkillDT = new DataTable();
            _sSkillList = new EmployeeOtherSkillsTableList();
            _sSkillList = EmployeeOtherSkillsTableManager.GetList(AccountID);
            //ateSkillTable(_sSkillList);
            gvEmployeeOtherSkills.DataSource = _sSkillList;//Session["EmployeeOtherSkillsDT"];
            gvEmployeeOtherSkills.DataBind();

        }
    }

    private void ClearOtherSkillRecord()
    {
        txtSkill.Text = string.Empty;
        txtSkillOrganization.Text = string.Empty;
        txtSkillLevel.Text = string.Empty;
        txtSkillOthers.Text = string.Empty;
        txtNoOfYear.Text = string.Empty;
    }

    private void ClearQualificationRecord()
    {
        txtQualification2.Text = string.Empty;
        txtOrganization.Text = string.Empty;
        txtYear.Text = string.Empty;
        txtGradelevel.Text = string.Empty;
        txtQualifyOthers.Text = string.Empty;
    }

    private void ClearSalaryRecord()
    {
        txtAmount.Text = string.Empty;
        txtAllotment1.Text = string.Empty;
        txtAllotment2.Text = string.Empty;
        txtSalaryStartDate.Text = string.Empty;
        txtSalaryEndDate.Text = string.Empty;
        txtSalaryRemark.Text = string.Empty;
        chkActive.Checked = false;
        ddlCurrency.SelectedIndex = 0;
        ddlpaymentType.SelectedIndex = 0;
    }

    private void ClearDesignationRecord()
    {
        txtDesignationDesc.Text = string.Empty;
        txtDesgnationStartDate.Text = string.Empty;
        txtDesgnationEndDate.Text = string.Empty;
        txtDesignationRemark.Text = string.Empty;
        chkDesignation.Checked = false;

    }

    private void FillEmployeeSalary(int AccountID)
    {

        DataTable lSalaryDT = new DataTable();
        EmployeeSalaryTableList _sEmployeeSalaryList = new EmployeeSalaryTableList();
        _sEmployeeSalaryList = EmployeeSalaryTableManager.GetList(AccountID);
        gvSalary.DataSource = _sEmployeeSalaryList;
        gvSalary.DataBind();
    }

    private void FillEmployeeJobExperience(int AccountID)
    {

        //Job Experiences
        DataTable lDT = new DataTable();
        EmployeeJobExperiencesTableList _sJobExperiencesList = new EmployeeJobExperiencesTableList();
        _sJobExperiencesList = EmployeeJobExperiencesTableManager.GetListByUserAccountKey(AccountID);
        dgExperienceBrowse.DataSource = _sJobExperiencesList;
        dgExperienceBrowse.DataBind();
    }

    private void FillEmployeeOtherSkill(int AccountID)
    {

        //Job Experiences
        DataTable lDT = new DataTable();
        EmployeeOtherSkillsTableList _sOtherSkillList = new EmployeeOtherSkillsTableList();
        _sOtherSkillList = EmployeeOtherSkillsTableManager.GetList(AccountID);
        gvEmployeeOtherSkills.DataSource = _sOtherSkillList;
        gvEmployeeOtherSkills.DataBind();
    }

    private void FillEmployeeDesignation(int AccountID)
    {

        //Job Experiences
        DataTable lDT = new DataTable();
        EmployeeDesignationTableList _sDesignationList = new EmployeeDesignationTableList();
        _sDesignationList = EmployeeDesignationTableManager.GetList(AccountID);
        gvDesignation.DataSource = _sDesignationList;
        gvDesignation.DataBind();
    }

    private void FillEmployeeQualification(int AccountID)
    {

        //Job Experiences
        DataTable lDT = new DataTable();
        EmployeeQualtificationTableList _sQualificationList = new EmployeeQualtificationTableList();
        _sQualificationList = EmployeeQualtificationTableManager.GetList(AccountID);
        dgvEmployeeQualtification.DataSource = _sQualificationList;
        dgvEmployeeQualtification.DataBind();
    }

    #endregion


    
}